package com.tongji.housediy.view.components
{
	import com.tongji.housediy.utils.MathCalculation;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.filters.GlowFilter;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	import mx.core.UIComponent;
	
	import spark.components.Label;
	
	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class ExternalRulerField extends AbstractRulerField
	{
		private var p3:Point, p4:Point;
		
		public function ExternalRulerField(p1X:Number, p1Y:Number, p2X:Number, p2Y:Number, k:Number)
		{
			super(p1X, p1Y, p2X, p2Y, k, 40);
			
			var middlePoint:Point = Point.interpolate(p3, p4, 0.5);
			textField.x = middlePoint.x - textField.width / 2;
			textField.y = middlePoint.y - textField.height / 2;
		}
		
		public function updateRulerField(p1X:Number, p1Y:Number, p2X:Number, p2Y:Number, k:Number):void
		{
			updatePointData(p1X, p1Y, p2X, p2Y, k, 40);
			
			textField.text = int(Point.distance(s1, s2)) + ' cm';
			
			var middlePoint:Point = Point.interpolate(p3, p4, 0.5);
			textField.x = middlePoint.x - textField.width / 2;
			textField.y = middlePoint.y - textField.height / 2;
		}
		
		override protected function updatePointData(p1X:Number, p1Y:Number, p2X:Number, p2Y:Number, k:Number, length:Number):void
		{
			super.updatePointData(p1X, p1Y, p2X, p2Y, k, length);
			
			p3 = Point.interpolate(new Point(p1X, p1Y), p1, 0.1);
			p4 = Point.interpolate(new Point(p2X, p2Y), p2, 0.1);
			
			this.graphics.clear();
			this.graphics.lineStyle(1, 0x000000);
			this.graphics.moveTo(s1.x, s1.y);
			this.graphics.lineTo(p1.x, p1.y);
			this.graphics.moveTo(s2.x, s2.y);
			this.graphics.lineTo(p2.x, p2.y);
			this.graphics.moveTo(p3.x, p3.y);
			this.graphics.lineTo(p4.x, p4.y);			
		}
	}
}